﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ECare.BUS;
using ECare.BUS.Data;
using ECare.Client.templates;

namespace ECare.Client.frms
{
    public partial class frmPlanCheckInfo : frmInfo
    {
        public frmPlanCheckInfo()
        {
            InitializeComponent();



            this.Load += frmPlanCheckInfo_Load;
        }

        public override void LoadInfor()
        {
            base.LoadInfor();

            this.ucPlanInfo1.Plan = this.entity as PlanInfo;
            this.ucPlanCheckInfo1.Plan = this.entity as PlanInfo;
        }

        void frmPlanCheckInfo_Load(object sender, EventArgs e)
        {
            if (this.entity != null)
            {
        

            }

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            var planInfo = this.entity as PlanInfo;


            var originalstatus = (int) planInfo.checkstatus;

            if (this.rbAccespted.Checked)
            {
                planInfo.checkstatus = PlanStatus.qualified;

            }
            else if (this.rbRejected.Checked)
            {
                planInfo.checkstatus = PlanStatus.rejected;
            }
            else
            {
                planInfo.checkstatus = PlanStatus.draft;
            }


            //生成一条审批记录...
            if (originalstatus != (int)planInfo.checkstatus)
            {
                var recordinfo = new CheckInfo
                {
                    Check_By = ApplicationData.CurrentUserInfo.UserId,
                    Check_Time = DateTime.Now,
                    CheckType = CheckType.Plan,Current_Status = (int)planInfo.checkstatus,
                    EntityId = planInfo.plan_id,
                    Original_Status = originalstatus,
                    Remark = this.txtCheckRemark.Text
                };
                CheckRecordsHelper.CreateCheck(recordinfo);
            }







            if (string.IsNullOrEmpty(planInfo.plan_check_remark))
            {
                planInfo.plan_check_remark = string.Format("[{0}],[{1}],[{2}]", 0, DateTime.Now, this.txtCheckRemark.Text);
            }
            else
            {
                planInfo.plan_check_remark = planInfo.plan_check_remark + "\n\t";
                planInfo.plan_check_remark = planInfo.plan_check_remark + string.Format("[{0}],[{1}],[{2}]", 0, DateTime.Now, this.txtCheckRemark.Text);
            }
            planInfo.plan_check_by = ApplicationData.CurrentUserInfo.UserId;
            planInfo.plan_check_time = DateTime.Now;

            PlanHelper.CheckPlan(planInfo);

            this.Close();
        }
    }
}
